using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using Entities;
namespace DAL
{
   public class tbHinhthucrhanhtoanDAL
    {
       private SqlConnection cn = null;
       public tbHinhthucrhanhtoanDAL()
        {
            cn = new SqlConnection(ConfigurationManager.ConnectionStrings["strConnection"].ConnectionString);
            cn.Open();
        }
        public void Insert(tbHinhthucthanhtoan httt)
        {
            SqlCommand cm = new SqlCommand("Hinh_thuc_thanhtoan_Insert", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Tenhttt", httt.Tenhttt);
            cm.Parameters.AddWithValue("@Motathem", httt.Motathem);
            cm.ExecuteNonQuery();
        }
        public void Update(tbHinhthucthanhtoan httt)
        {
            SqlCommand cm = new SqlCommand("Hinh_thuc_thanhtoan_Update", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Matt", httt.Matt);
            cm.Parameters.AddWithValue("@Tenhttt",httt.Tenhttt);
            cm.Parameters.AddWithValue("@Motathem", httt.Motathem);
            cm.ExecuteNonQuery();
        }
        public void Delete(int iD)
        {
            SqlCommand cm = new SqlCommand("Hinh_thuc_thanhtoan_Delete", cn);
            cm.CommandType = CommandType.StoredProcedure;
            cm.Parameters.AddWithValue("@Matt", iD);
            cm.ExecuteNonQuery();
        }
      public tbHinhthucthanhtoanColection Get(string where, int pageIndex, int pageSize, string orderBy, string orderDirection, out int totalRecords)
      {
          SqlCommand cm = new SqlCommand("Hinh_thuc_thanhtoan_Get", cn);
          cm.CommandType = CommandType.StoredProcedure;
          cm.Parameters.AddWithValue("@Where", where);
          cm.Parameters.AddWithValue("@PageIndex", pageIndex);
          cm.Parameters.AddWithValue("@PageSize", pageSize);
          cm.Parameters.AddWithValue("@OrderBy", orderBy);
          cm.Parameters.AddWithValue("@OrderDirection",orderDirection);
          cm.Parameters.Add(new SqlParameter("@TotalRecords",DbType.Int32)).Direction =ParameterDirection.Output;
          SqlDataReader dr = cm.ExecuteReader();
          tbHinhthucthanhtoanColection htttCOllection = new tbHinhthucthanhtoanColection();
          while (dr.Read())
          {
              tbHinhthucthanhtoan httt = new tbHinhthucthanhtoan();
             httt.Matt= int .Parse(dr.GetValue(0).ToString());
             httt.Tenhttt = (dr.GetValue(1).ToString());
             httt.Motathem = (dr.GetValue(2).ToString());
             htttCOllection.Add(httt);
          }
          dr.Close();
          totalRecords = int.Parse(
          cm.Parameters["@TotalRecords"].Value.ToString());
          return htttCOllection;
      }
    
    }
}
